package com.hey.jvm;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryUsage;

public class ManegeSample {
    public static void main(String[] args) {

        byte [] data = new byte[1024 * 1024 * 100];
        System.out.println("ManegeSample...");
        ManagementFactory.getPlatformMBeanServer();
        for (MemoryPoolMXBean mpb : ManagementFactory.getMemoryPoolMXBeans()) {
            String name = mpb.getName();
            System.out.println(name + ": -----------" );
            MemoryUsage memoryUsage = mpb.getCollectionUsage();
            if(memoryUsage == null){
                continue;
            }
            System.out.println(name + " Committed: " + memoryUsage.getCommitted());
            System.out.println(name + " Used: " +  memoryUsage.getUsed());
            System.out.println(name + " Init: " + memoryUsage.getInit());
            System.out.println(name + " Max: " + memoryUsage.getMax());
        };
    }
}
